package com.cn.sun.esdemo.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @ClassName EsUtilConfigClint
 * @Author jiang_11445266119198
 * @Date 2022/10/7 0:23
 */
@Configuration
public class EsUtilConfigClint {

    /**
     * 客户端
     * @return
     */
   /* public ElasticsearchClient configClint() {
        // Create the low-level client
        RestClient restClient = RestClient.builder(
                new HttpHost("192.168.0.174", 9200)).build();

        // Create the transport with a Jackson mapper
        ElasticsearchTransport transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());

        // 客户端
        ElasticsearchClient client = new ElasticsearchClient(transport);

        return client;
    }*/

    public ElasticsearchClient elasticsearchClient(){
        RestClient client = RestClient.builder(new HttpHost("192.168.0.174", 9200,"http")).build();
        ElasticsearchTransport transport = new RestClientTransport(client,new JacksonJsonpMapper());
        return new ElasticsearchClient(transport);
    }
}
